

#ifndef __CE_MATERIALMANAGER_H__
#define __CE_MATERIALMANAGER_H__

#include <cegfx/ceeffect.h>
#include <cegfx/ceexport.h>
#include <cegfx/iloading.h>
#include <cegfx/cematerial.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <list>
#include <string>
#include <cecore/cetypes.h>

class CE_GFX_API ceMaterialManager 
{
private:
	struct BaseData
	{
		ceString		Name;
		ceString		Filename;
	};

	struct TextureData : BaseData
	{
		LPDIRECT3DTEXTURE9	Texture;
	};

	struct EffectData : BaseData
	{
		ceEffect*	Effect;
	};

	struct MaterialData : BaseData
	{
		ceMaterial* Material;
	};


	std::list<TextureData>		textures;
	std::list<EffectData>			effects;
	std::list<MaterialData>		materials;

	std::list<iTextureLoader*>	textureLoader;
	std::list<iEffectLoader*>		effectLoader;
	std::list<iMaterialLoader*>	materialLoader;


	LPDIRECT3DDEVICE9 device;

	iFile* openFile (const ceString& filename);

	iTextureLoader*		getTextureLoader (iFile* file);
	iEffectLoader*		getEffectLoader (iFile* file);
	iMaterialLoader*	getMaterialLoader (iFile* file);

	static ceMaterialManager* static_instance;
private:
	ceMaterialManager (LPDIRECT3DDEVICE9 device);
	~ceMaterialManager ();

public:
	static ceMaterialManager* Initialize (LPDIRECT3DDEVICE9 device);
	static ceMaterialManager* Initialize (ceMaterialManager* other);
	static ceMaterialManager* Get ();

	virtual void AddTexture (const ceString& name, LPDIRECT3DTEXTURE9 texture);
	virtual void AddEffect (const ceString& name, ceEffect* effect);
	virtual void AddMaterial (const ceString& name, ceMaterial* material);

	virtual void RemoveTexture (const ceString& name);
	virtual void RemoveEffect (const ceString& name);
	virtual void RemoveMaterial (const ceString& name);

	virtual void RegisterTexture (const ceString& name, const ceString& filename);
	virtual void RegisterEffect (const ceString& name, const ceString& filename);
	virtual void RegisterMaterial (const ceString& filename);
	virtual void RegisterMaterial (const ceString& name, const ceString& filename);

	virtual bool HasTexture (const ceString& name) const;
	virtual bool HasEffect (const ceString& name) const;
	virtual bool HasMaterial (const ceString& name) const;

	virtual LPDIRECT3DTEXTURE9 GetTexture (const ceString& name);
	virtual ceEffect* GetEffect (const ceString& name);
	virtual ceMaterial* GetMaterial (const ceString& name);

	void AddTextureLoader (iTextureLoader* loader);
	void AddEffectLoader (iEffectLoader* loader);
	void AddMaterialLoader (iMaterialLoader* loader);
};


#endif /* ! __CE_MATERIALMANAGER_H__ */ 
